package com.bjsxt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bjsxt.domain.InventoryLog;
import com.bjsxt.dto.InventoryLogDto;
import com.bjsxt.mapper.InventoryLogMapper;
import com.bjsxt.service.InventoryLogService;
import com.bjsxt.vo.DataGridView;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author:liao
 * @Description:TODO
 * @date:2021/1/10
 */
@Service
public class InventoryServiceImpl implements InventoryLogService {

    @Autowired
    private InventoryLogMapper inventoryLogMapper;

    // 分页查询入库日志信息
    @Override
    public DataGridView listInventoryPage(InventoryLogDto inventoryLogDto) {
        Page<InventoryLog> page = new Page<>(inventoryLogDto.getPageNum(),inventoryLogDto.getPageSize());
        QueryWrapper<InventoryLog> qw = new QueryWrapper<>();
        // 根据采购单据号模糊查询
        qw.like(StringUtils.isNotBlank(inventoryLogDto.getPurchaseId()),InventoryLog.COL_PURCHASE_ID,inventoryLogDto.getPurchaseId());
        // 根据药品名称模糊查询
        qw.like(StringUtils.isNotBlank(inventoryLogDto.getMedicinesName()),InventoryLog.COL_MEDICINES_NAME,inventoryLogDto.getMedicinesName());
        // 根据药品类型查询
        qw.eq(StringUtils.isNotBlank(inventoryLogDto.getMedicinesType()),InventoryLog.COL_MEDICINES_TYPE,inventoryLogDto.getMedicinesType());
        // 根据生产厂家查询
        qw.eq(StringUtils.isNotBlank(inventoryLogDto.getProducterId()),InventoryLog.COL_PRODUCTER_ID,inventoryLogDto.getProducterId());
        // 根据处方类型查询
        qw.eq(StringUtils.isNotBlank(inventoryLogDto.getPrescriptionType()),InventoryLog.COL_PRESCRIPTION_TYPE,inventoryLogDto.getPrescriptionType());
        // 根据创建时间进行查询
        qw.ge(null!=inventoryLogDto.getBeginTime(),InventoryLog.COL_CREATE_TIME,inventoryLogDto.getBeginTime());
        qw.le(null!=inventoryLogDto.getEndTime(),InventoryLog.COL_CREATE_TIME,inventoryLogDto.getEndTime());
        // 根据创建时间进行降序
        qw.orderByDesc(InventoryLog.COL_CREATE_TIME);
        this.inventoryLogMapper.selectPage(page,qw);
        return new DataGridView(page.getTotal(),page.getRecords());
    }
}
